<?php
namespace Home\Controller;
use Think\Controller;
class PublicController extends Controller 
{
    function getIPaddress(){
//        $IPaddress='';
//        if (isset($_SERVER)){
//            if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])){
//                $IPaddress = $_SERVER["HTTP_X_FORWARDED_FOR"];
//            } else if (isset($_SERVER["HTTP_CLIENT_IP"])) {
//                $IPaddress = $_SERVER["HTTP_CLIENT_IP"];
//            } else {
//                $IPaddress = $_SERVER["REMOTE_ADDR"];
//            }
//        } else {
//            if (getenv("HTTP_X_FORWARDED_FOR")){
//                $IPaddress = getenv("HTTP_X_FORWARDED_FOR");
//            } else if (getenv("HTTP_CLIENT_IP")) {
//                $IPaddress = getenv("HTTP_CLIENT_IP");
//            } else {
//                $IPaddress = getenv("REMOTE_ADDR");
//            }
//        }
//        return $IPaddress;
    }
    function getip(){
//        $clientIP=get_client_ip();
//        $taobaoIP = 'http://ip.taobao.com/service/getIpInfo.php?ip='.$clientIP;
//        $IPinfo = json_decode(file_get_contents($taobaoIP));
//        $province = $IPinfo->data->region;
//        $city = $IPinfo->data->city;
//        $data = $city;
//        $this->assign('data',$data);
//        import('ORG.Net.IpLocation');// 导入IpLocation类
            $url="http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
            preg_match("#http://(.*?)\.#i ",$url,$match);
            if($match[1]==www){
                $Ip = new \Org\Net\IpLocation('qqwry.dat');
                $ip = get_client_ip();
                $arr = $Ip->getlocation($ip);
                $country = $arr["country"];
                $city = iconv("GB2312","UTF-8",$country);
                $arr = explode(省,$city);
                $data=$arr["1"];
            }else{
                $url="http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
                preg_match("#http://(.*?)\.#i ",$url,$match);
                $cityOb = M("City");
                $arr = $cityOb->where("pinyin='$match[1]'")->find();
                $data = $arr['name'];
            }
        //$py = new \Org\Util\Pinyin;
       // $data = $py->qupinyin($city);
        $this->assign('data',$data);
    }
    function layout(){
       session_start();
      if(isset($_SESSION['username'])){
           // session_unset();//free all session variable
            session_destroy();//销毁一个会话中的全部数据
            echo "<script>alert('退出成功');parent.location.href='index';</script>";
        }else{
          echo "<script>alert('退出失败');parent.location.href='index';</script>";
        }
    }
    function zhuanpy(){
        $py = new \Org\Util\Pinyin;

        echo $py->qupinyin('汉字');
       // --- hanzi
        echo $py->qupinyin('汉字',true);
        //--- hz
        echo $py->qupinyin('汉####字',true);
       // --- h____z
        echo $py->qupinyin('汉####字',true,'/');
       // --- h////z
    }
}